#include <iostream>
#include <stack>
#include <string>

bool isValidBracketSequence(const std::string& sequence) {
    std::stack<char> stack;
    for (char bracket : sequence) {
        if (bracket == '(' || bracket == '[' || bracket == '{' || bracket == '<') {
            stack.push(bracket);
        } else if (bracket == ')' || bracket == ']' || bracket == '}' || bracket == '>') {
            if (stack.empty()) {
                return false;
            }
            char openBracket = stack.top();
            stack.pop();
            if ((openBracket == '(' && bracket != ')') ||
                (openBracket == '[' && bracket != ']') ||
                (openBracket == '{' && bracket != '}') ||
                (openBracket == '<' && bracket != '>')) {
                return false;
            }
        }
    }
    return stack.empty();
}

int main() {
    std::string sequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> sequence;
    if (isValidBracketSequence(sequence)) {
        std::cout << "True" << std::endl;
    } else {
        std::cout << "False" << std::endl;
    }
    return 0;
}